package com.project.myshop.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StringUtils {
    public static boolean isNotEmpty(String... strs){
        for (String str : strs) {
            if (str==null||str.trim().length()==0) {
                return false;
            }
        }
        return true;
    }

    public static int stringToInt(String num){
        try {
            return isNotEmpty(num)?Integer.valueOf(num):-1;
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return -1;
    }
    public static Double stringToDouble(String num){
        try {
            return isNotEmpty(num)?Double.valueOf(num):-1;
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return -1D;
    }


    public static Date stringToDate(String time){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return sdf.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
